<!-- daterange picker -->
<link rel="stylesheet" href="__PUBLIC__/AdminLTE/plugins/daterangepicker/daterangepicker.css">
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            业务员统计
            <if condition="$department_id gt 0">
                <small>【{$department_name}】</small>
            </if>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">系统统计</li>
            <li class="active">业务员统计</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
                <form class="form-inline" action="/admin/stat/manageStaffStatList" method="get">
                    <div class="form-group">
                        <label for="name">姓名 </label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="姓名" value="{$name}">
                    </div>
                    <div class="form-group">
                        <label class="label-control" for="department_id">部门 </label>
                        <select id="department_id" name="department_id" class="form-control">
                            <option value="0">请选择</option>
                            <foreach name="departmentList" item="department">
                                <option value="{$department.id}" <if condition="$department.id eq $department_id ">selected</if>>{$department.name}</option>
                            </foreach>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-info" id="save-btn">查询</button>&nbsp;
                    <button type="button" class="btn btn-primary" id="export-btn"  onclick="window.location.href='/admin/stat/manageStaffStatExport?name={$name}&department_id={$department_id}'">导出</button>&nbsp;
                    <button type="button" class="btn btn-danger btn-md pull-right" data-toggle="modal" data-target="#myModal">导出全部</button>
                </form>
            </div>
            <div class="box-body">
                <table class="table table-bordered">
                    <tbody>
                    <tr>
                        <th>ID</th>
                        <th>角色</th>
                        <th>部门</th>
                        <th>姓名</th>
                        <th>总客户数</th>
                        <th>总订单数</th>
                        <th>成单数</th>
                        <th>进行中</th>
                        <th>销售额</th>
                        <th>成本金额</th>
                        <th>其他费用</th>
                        <th>操作</th>
                    </tr>
                    <if condition="count($userList) eq 0"><tr><td class="text-center" colspan="12">暂无数据...</td></tr></if>
                    <foreach name="userList" item="user">
                            <tr>
                                <td>{$user.id}</td>
                                <td>{$user.user_group_name}</td>
                                <td>{$user.department_name}</td>
                                <td>{$user.name}</td>
                                <td>{$user.all_customer}</td>
                                <td>{$user.all_order}</td>
                                <td>{$user.over_order}</td>
                                <td>{$user.going_order}</td>
                                <td>{$user.total_amount|default='0'}</td>
                                <td>{$user.total_base_price|default='0'}</td>
                                <td>{$user.total_other_price|default='0'}</td>
                                <td>
                                    <button class="btn btn-primary btn-xs" type="button" onclick="window.location.href='/admin/stat/staffStatOrderList?admin_id={$user.id}'">详情</button>&nbsp;
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">订单导出</h4>
            </div>
            <form class="form-inline" action="/admin/stat/manageExportOrderList" method="get">

                <div class="modal-body">
                    <div class="form-group">
                        <label for="admin_id">人员 </label>
                        <select id="admin_id" name="admin_id" class="form-control">
                            <option value="0">请选择</option>
                            <foreach name="userList" item="user">
                                <option value="{$user.id}">{$user.name}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>客户录入时间</label>
                        <div class="input-group">
                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                            <input type="text" class="form-control pull-right" name="search_time" id="export_time" value="">
                        </div>
                        <!-- /.input group -->
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" id="export_order">导出</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- date-range-picker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/daterangepicker/daterangepicker.js"></script>
<script type="application/javascript">
    $("#export_order").click(function () {
        $("#myModal").modal('hide');
    });
    $(function () {
        //Date range picker
        $('#reservation').daterangepicker({
            autoUpdateInput: false,
            applyClass : 'btn-sm btn-success',
            cancelClass : 'btn-sm btn-default',
            locale: {
                applyLabel: '确认',
                cancelLabel: '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                weekLabel: 'W',
                daysOfWeek:['日','一','二','三','四','五','六'],
                monthNames:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                firstDay : 1
            },
            startDate: new Date(),
            endDate: new Date(),
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                '最近7天': [moment().subtract(6, 'days'), moment()],
                '最近30天': [moment().subtract(29, 'days'), moment()],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        });
        $('#reservation').on('apply.daterangepicker', function(ev, picker) {
            $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
        });
        $('#reservation').on('cancel.daterangepicker', function(ev, picker) {
            $(this).val('');
        });


        $('#export_time').daterangepicker({
            autoUpdateInput: false,
            applyClass : 'btn-sm btn-success',
            cancelClass : 'btn-sm btn-default',
            locale: {
                applyLabel: '确认',
                cancelLabel: '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                weekLabel: 'W',
                daysOfWeek:['日','一','二','三','四','五','六'],
                monthNames:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                firstDay : 1
            },
            startDate: new Date(),
            endDate: new Date(),
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                '最近7天': [moment().subtract(6, 'days'), moment()],
                '最近30天': [moment().subtract(29, 'days'), moment()],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        });
        $('#export_time').on('apply.daterangepicker', function(ev, picker) {
            $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
        });
        $('#export_time').on('cancel.daterangepicker', function(ev, picker) {
            $(this).val('');
        });
    });
</script>